/*
 * LiquidBounce Hacked Client
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
 * https://github.com/CCBlueX/LiquidBounce/
 */
package net.ccbluex.liquidbounce.ui.client.hud.element.elements

import me.utils.render.RoundedUtil
import me.utils.render.ShadowUtils
import net.ccbluex.liquidbounce.LiquidBounce
import net.ccbluex.liquidbounce.features.module.modules.color.ColorMixer
import net.ccbluex.liquidbounce.features.module.modules.render.HUD
import net.ccbluex.liquidbounce.features.module.modules.render.PictureColor
import net.ccbluex.liquidbounce.features.module.modules.render.PictureColor2
import net.ccbluex.liquidbounce.features.module.modules.render.RenderPosHelper
import net.ccbluex.liquidbounce.font.CFontLoad
import net.ccbluex.liquidbounce.ui.client.hud.element.Border
import net.ccbluex.liquidbounce.ui.client.hud.element.Element
import net.ccbluex.liquidbounce.ui.client.hud.element.ElementInfo
import net.ccbluex.liquidbounce.utils.EntityUtils
import net.ccbluex.liquidbounce.utils.ServerUtils
import net.ccbluex.liquidbounce.utils.blur.BlurBuffer
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils
import net.ccbluex.liquidbounce.value.BoolValue
import net.ccbluex.liquidbounce.value.ListValue
import net.minecraft.client.renderer.GlStateManager
import org.lwjgl.opengl.GL11
import java.awt.Color

/**
 * CustomHUD effects element
 *
 * Shows a list of active potion effects
 */
@ElementInfo(name = "Clientlogo")
class ClientLogo (x: Double = 29.0, y: Double = 20.0) : Element() {


    private val colorModeValue = ListValue("mode", arrayOf("old","new"), "new")
    private val shadow = BoolValue("Shadow", true)

    /**
     * Draw element
     */
    var color = LiquidBounce.moduleManager.getModule(PictureColor::class.java) as PictureColor
    var color2 = LiquidBounce.moduleManager.getModule(PictureColor2::class.java) as PictureColor2
    var renpos = LiquidBounce.moduleManager.getModule(RenderPosHelper::class.java) as RenderPosHelper
    var blurmodule = LiquidBounce.moduleManager.getModule(HUD::class.java) as HUD
    override fun drawElement(): Border {
        var returnwith = 0f
        var displayText: String = LiquidBounce.CLIENT_NAME
        var gradientColor1 = Color.WHITE
        var gradientColor2 = Color.WHITE
        var gradientColor3 = Color.WHITE
        var gradientColor4 = Color.WHITE

        gradientColor1 = ColorUtils.interpolateColorsBackAndForth(10, 20,Color(color.colorRedValue.get(), color.colorGreenValue.get(), color.colorBlueValue.get(),color.coloralpha.get()), Color(color2.colorRedValue.get(), color2.colorGreenValue.get(), color2.colorBlueValue.get(),color2.coloralpha.get()), false)
        gradientColor2 = ColorUtils.interpolateColorsBackAndForth(20, 90,Color(color2.colorRedValue.get(), color2.colorGreenValue.get(), color2.colorBlueValue.get(),color.coloralpha.get()), Color(color2.colorRedValue.get(), color2.colorGreenValue.get(), color2.colorBlueValue.get(),color2.coloralpha.get()), false)
        gradientColor3 = ColorUtils.interpolateColorsBackAndForth(20, 270, Color(color.colorRedValue.get(), color.colorGreenValue.get(), color.colorBlueValue.get(),color.coloralpha.get()),Color(color.colorRedValue.get(), color.colorGreenValue.get(), color.colorBlueValue.get(),color2.coloralpha.get()), false)
        gradientColor4 = ColorUtils.interpolateColorsBackAndForth(20, 270, Color(color2.colorRedValue.get(), color2.colorGreenValue.get(), color2.colorBlueValue.get(),color.coloralpha.get()), Color(color2.colorRedValue.get(), color2.colorGreenValue.get(), color2.colorBlueValue.get(),color2.coloralpha.get()), false)
        var text2 = LiquidBounce.CLIENT_NAME

        var text = text2+" | "+ LiquidBounce.CLIENT_VERSION+" | "+mc.debugFPS+"fps"
        if (colorModeValue.get().equals("old")){
            if (blurmodule.blurmoduleValue.get()){
                GL11.glTranslated(-renderX, -renderY, 0.0)
                BlurBuffer.blurRoundArea(renderX.toFloat()-8.20f,renderY.toFloat()-4.0f,(text.length*5.55f),15.40f,3)
                GL11.glTranslated(renderX, renderY, 0.0)
            }

            RoundedUtil.drawGradientRound(-7.32f,-3.66f,(text.length*5.49f),14.63f,3f,gradientColor1,gradientColor3,gradientColor2,gradientColor1)
            CFontLoad.newforever20.drawStringWithShadow(text2,0.85,+0.75,Color(255,60,60,255).rgb)
            CFontLoad.newforever20.drawStringWithShadow(text2,-0.7,-0.7,Color(0,255,255,255).rgb)
            CFontLoad.newforever20.drawStringWithShadow(text,0.0,0.0,Color(255,255,255,255).rgb)

        }
       if (colorModeValue.get().equals("new")){
           var V = LiquidBounce.CLIENT_VERSION
           var ping = EntityUtils.getPing(mc2.player).toString()
           var ip = ServerUtils.getRemoteIp()
           var fps = mc.debugFPS
           var times = Text.HOUR_FORMAT.format(System.currentTimeMillis())
           val floatX = renderX.toFloat()
           val floatY = renderY.toFloat()
           var clientname = LiquidBounce.CLIENT_NAME
           var lengt =" | " + V + " | " + times + " | " + ip + " | " + ping + "ping" + " | " + fps + "fps"
           var with2 = CFontLoad.for16.getStringWidth(lengt+clientname)
           returnwith = with2.toFloat()

           if (shadow.get()){
               GL11.glTranslated(-renderX, -renderY, 0.0)
               GL11.glScalef(1F, 1F, 1F)
               GL11.glPushMatrix()
               ShadowUtils.shadow(8f, {
                   GL11.glPushMatrix()
                   GL11.glTranslated(renderX, renderY, 0.0)
                   GL11.glScalef(scale, scale, scale)
                   RenderUtils.originalRoundedRect(
                       -20.70f,
                       36f,-20.70f+(clientname.length+lengt.length)*4.10f+1f,36.2f+16.25f,
                       2f,Color(0,0,0,210).rgb)


                   GL11.glPopMatrix()
               }, {

                   GL11.glPushMatrix()
                   GL11.glTranslated(renderX, renderY, 0.0)
                   GL11.glScalef(scale, scale, scale)
                   GlStateManager.enableBlend()
                   GlStateManager.disableTexture2D()
                   GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)

                   RenderUtils.originalRoundedRect(
                       -20.70f,
                       36f,-20.70f+(clientname.length+lengt.length)*4.10f+1f,36.2f+16.25f,
                       2f,Color(blurmodule.shadowred.get(),blurmodule.shadowgreen.get(),blurmodule.shadowblue.get(),blurmodule.shadowalpha.get()).rgb)
                   GlStateManager.enableTexture2D()
                   GlStateManager.disableBlend()
                   GL11.glPopMatrix()
               })
               GL11.glPopMatrix()
               GL11.glScalef(scale, scale, scale)
               GL11.glTranslated(renderX, renderY, 0.0)
           }
           RoundedUtil.drawRound(-20f,36.59f,(clientname.length+lengt.length)*4f+5f,15f,2f,Color(0, 0, 0, 200))


           var stringZ = ""
           for (i in 0..clientname.length-1) {

               CFontLoad.clientfont20.drawStringWithShadow(clientname.get(i).toString(),-14.0.toDouble()+ CFontLoad.clientfont20.getStringWidth(stringZ),43.90.toDouble(),ColorMixer.getMixedColor(-i * 10 * 10,1.toInt()).rgb)
               stringZ += clientname.get(i).toString()
           }





           CFontLoad.for16.drawStringWithShadow(lengt,clientname.length*4.toDouble(),42.0.toDouble(),Color.WHITE.rgb)
       }
        return Border(2.0f - 15.0f, 2.0f - 18.0f, 2.0f + 190.0f, 2.0f + 78.0f)
    }
    fun getFadeProgress() = 0f
    fun getColor(color: Color) = ColorUtils.reAlpha(color, color.alpha / 255F * (1F - getFadeProgress()))
    fun getColor(color: Int) = getColor(Color(color))

}